#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>

int main(int argc,char **argv)
{
    pid_t pid;
    // if(mkfifo("./file",0655)<0)
    // {
    //     perror("mkfifo error\n");
    //     exit(1);
    // }
    pid=fork();
    if(pid<0)
    {
        perror("fork error\n");
        exit(1);
    }
    if(pid == 0)
    {
        int fd=open("./file",O_WRONLY);
        char buff[1024];
        while (1)
        {
            memset(buff,0,1024);
            scanf("%s",buff);
            //read(fd[0],buff,sizeof(buff));
            write(fd,buff,strlen(buff));
        }
        
    }
    else if(pid > 0 )
    {
        int fd=open("./file",O_RDONLY);
        char buff[1024];
       
        while (1)
        {
          memset(buff,0,1024);
           // scanf("%s",buff);
           // printf("send:%s\n",buff);
           read(fd,buff,sizeof(buff));
           printf("%s\n",buff);
        }
        
    }
    return 0;
}